#import "SSCarrierInfo.h"
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
@implementation SSCarrierInfo
+ (NSString *)carrierName {
    @try {
        CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
        CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];
        NSString *carrierName = [carrier carrierName];
        if (carrierName == nil || carrierName.length <= 0) {
            return nil;
        }
        return carrierName;
    }
    @catch (NSException *exception) {
        return nil;
    }
}
+ (NSString *)carrierCountry {
    @try {
        NSLocale *currentCountry = [NSLocale currentLocale];
        NSString *country = [currentCountry objectForKey:NSLocaleCountryCode];
        if (country == nil || country.length <= 0) {
            return nil;
        }
        return country;
    }
    @catch (NSException *exception) {
        return nil;
    }
}
+ (NSString *)carrierMobileCountryCode {
    @try {
        CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
        CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];
        NSString *carrierCode = [carrier mobileCountryCode];
        if (carrierCode == nil || carrierCode.length <= 0) {
            return nil;
        }
        return carrierCode;
    }
    @catch (NSException *exception) {
        return nil;
    }
}
+ (NSString *)carrierISOCountryCode {
    @try {
        CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
        CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];
        NSString *carrierCode = [carrier isoCountryCode];
        if (carrierCode == nil || carrierCode.length <= 0) {
            return nil;
        }
        return carrierCode;
    }
    @catch (NSException *exception) {
        return nil;
    }
}
+ (NSString *)carrierMobileNetworkCode {
    @try {
        CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
        CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];
        NSString *carrierCode = [carrier mobileNetworkCode];
        if (carrierCode == nil || carrierCode.length <= 0) {
            return nil;
        }
        return carrierCode;
    }
    @catch (NSException *exception) {
        return nil;
    }
}
+ (BOOL)carrierAllowsVOIP {
    @try {
        CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
        CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];
        BOOL carrierVOIP = [carrier allowsVOIP];
        return carrierVOIP;
    }
    @catch (NSException *exception) {
        return false;
    }
}
@end
